package com.framework.tomcat.ex03.pyrmont;

import com.framework.tomcat.ex03.pyrmont.connector.http.HttpConnector;
import com.framework.tomcat.ex03.pyrmont.core.SimpleContextConfig;
import org.apache.catalina.*;
import org.apache.catalina.core.StandardContext;
import org.apache.catalina.loader.WebappLoader;

import java.io.IOException;

/**
 * @author LIN
 * @date 2022-08-06 16:21
 */
public class Main {

    public static void main(String[] args) throws IOException, LifecycleException {

        System.setProperty("catalina.home","D:\\project-2022\\tomcat\\apache-tomcat-6.0.9");
        System.setProperty("catalina.base","D:\\project-2022\\tomcat\\apache-tomcat-6.0.9");
        HttpConnector connector = new HttpConnector();
        Context context = new StandardContext();
        connector.setContainer(context);


        context.setPath("/webProject");
        context.setDocBase("webapps\\examples");

        LifecycleListener listener = new SimpleContextConfig();
        ((Lifecycle)context).addLifecycleListener(listener);

        Wrapper wrapper1 = context.createWrapper();
        wrapper1.setName("com.framework.servlet.InitServlet1");
        context.addChild(wrapper1);
        context.addServletMapping("/init","com.framework.servlet.InitServlet1");

        Loader loader = new WebappLoader();

        context.setLoader(loader);
        connector.initialize();
        ((Lifecycle)connector).start();
        ((Lifecycle) context).start();

        System.in.read();
        ((Lifecycle) context).stop();
//        WebappClassLoader classLoader = (WebappClassLoader) loader.getClassLoader();
//        ((ProxyDirContext)classLoader.getResources()).getDocBase();

//        String[] repositories = classLoader.findRepositories();
//        for (String repository : repositories) {
//
//            System.out.println(repository);
//        }


    }


}
